//
//  PersonCenterOrdersView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/15.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "PersonCenterOrdersView.h"

@interface PersonCenterOrdersView()<UIGestureRecognizerDelegate>

///全部订单view
@property (nonatomic,strong) UIView *allOrdersView;

///订单栏目 背景view
@property (nonatomic,strong) UIView *ordersBgView;

@end

@implementation PersonCenterOrdersView

-(id)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    
    [self initAllOrdersView];
    [self initOrdersBgView];
}

//邀请标题view
-(void)initAllOrdersView{
    
    self.allOrdersView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 38)];
    self.allOrdersView.backgroundColor = Color_Clear;
    [self addSubview:self.allOrdersView];
    
    self.allOrdersView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchAllOrderClick:)];
    tap.delegate = self;
    [self.allOrdersView addGestureRecognizer:tap];
    
    UILabel *leftLB = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 100, 25)];
    leftLB.textColor = MainBlackTextColor;
    leftLB.font = FontSetWithWeight(18, 0.3f);
    leftLB.text = @"我的订单";
    [self.allOrdersView addSubview:leftLB];
    
    UILabel *detailLB = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 200, leftLB.top+3, 166, 18)];
    detailLB.textColor = MainPureColor(153);
    detailLB.font = FontSet(13);
    detailLB.text = @"查看全部";
    detailLB.textAlignment = NSTextAlignmentRight;
    [self.allOrdersView addSubview:detailLB];
    
    UIImageView *moreImgV = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth - 30, detailLB.top+3, 6, 12)];
    moreImgV.image = LoadImage(@"个人中心_查看全部");
    [self.allOrdersView addSubview:moreImgV];
}

-(void)initOrdersBgView{
    
    self.ordersBgView = [[UIView alloc] initWithFrame:CGRectMake(10, self.allOrdersView.bottom, ScreenWidth-20, 100)];
    self.ordersBgView.backgroundColor = UIColor.whiteColor;
    self.ordersBgView.clipsToBounds = YES;
    self.ordersBgView.layer.cornerRadius = 4;
    [self addSubview:self.ordersBgView];
    
    NSArray *arr = @[@"待付款",@"待发货",@"待收货",@"待评价",@"售后"];
    
    for (int i = 0; i<arr.count; i++) {
        int x = i%5;
        int y = i/5;
        NSString *imageName = [NSString stringWithFormat:@"个人中心_%@",arr[i]];
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(23+x*(24+(ScreenWidth-120-46-10)/4), 26 + y * 60, 24, 24)];
        img.image = LoadImage(imageName);
        [self.ordersBgView addSubview:img];
        
        UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(img.left-10, img.bottom+5, img.width+20, 18)];
        lb.textAlignment = NSTextAlignmentCenter;
        lb.font = FontSet(13);
        lb.text = arr[i];
        lb.textColor = MainBlackTextColor;
        [self.ordersBgView addSubview:lb];
        
        UIView *touchView = [[UIView alloc] initWithFrame:CGRectMake(x*((ScreenWidth-20)/5),26 + y * 60, (ScreenWidth-20)/5, 50)];
        touchView.backgroundColor = Color_Clear;
        touchView.tag = i;
        touchView.userInteractionEnabled = YES;
        [self.ordersBgView addSubview:touchView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchOrdersClick:)];
        tap.delegate = self;
        [touchView addGestureRecognizer:tap];
    }
}

-(void)touchOrdersClick:(UIGestureRecognizer *)tap{
    UIView *view = (UIView *)tap.view;
    NSInteger index = (NSInteger)view.tag;
    if (self.touchOrdersBlock) {
        self.touchOrdersBlock(index);
    }
}

-(void)touchAllOrderClick:(UIGestureRecognizer *)tap{
    if (self.touchAllOrdersBlock) {
        self.touchAllOrdersBlock();
    }
}


@end
